package servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import service.HouseholdrService;
import service.impl.HouseholdServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

@WebServlet("/SearchAll")
public class SearchHouseholdServlet extends HttpServlet{
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");//！！！这里注意必须写在第一位，utf-8大小写都可以
        Integer page = Integer.valueOf(request.getParameter("page"));
        Integer limit = Integer.valueOf(request.getParameter("limit"));
        HouseholdrService householdrService=new HouseholdServiceImpl();
        response.setContentType("text/html;charset=utf-8");
        Map<String,Object> searchAll = householdrService.searchAll(page, limit);
        PrintWriter out = response.getWriter();
        out.println(new ObjectMapper().writeValueAsString(searchAll));
    }
}
